import './ContractConfig'

// 合约上下文
export default class ContractContext {
  constructor(name) {
    const { abi, address } = ContractConfig[name]

    this.context = null
    this.name = name
    this.abi = abi
    this.address = address

    this.initContract()
  }

  // 初始化合约
  initContract() {
    try {
      console.log(`初始化合约：${this.name}`)
      this.context = new web3.eth.Contract(this.abi, this.address)
      console.log('初始化合约成功')
      console.log(this.context)
    } catch (err) {
      console.error('初始化合约失败')
      console.error(err)
    }
  }
}
